<?php
	/**
	* New User Quick Approve action
	* For Pray Online
	* 
	* Note: Permission set on openidmodule, because, loginmodule does not have permission
	*/

	if (!defined('EXPONENT')) exit('');

	// check permission first
	$loc=null;
	$loc->mod="openidmodule"; // because, loginmodule does not have permission, so we set permission on openidmodule
	$loc->src="";
	$loc->int="";
	if (exponent_permissions_check("edit_userprofile",$loc) ||
	exponent_permissions_check("administrate",$loc))
	{
		$id=-1;
		if (isset($_REQUEST['id']))
		{
			$id=intval($_REQUEST['id']);
			$mu=exponent_users_getUserById($id);

			// Nov 10, 2011 - trungdt - Support lock and un-lock
			$lock_mode=1; // default is lock :)
			if (isset($_REQUEST['lock']))
				$lock_mode=intval($_REQUEST['lock']);
			if ($lock_mode !=0 && $lock_mode != 1)
				$lock_mode=1;
			// End nov 10
			$mu->is_locked=$lock_mode;
			exponent_users_saveUser($mu);
			// send email to this user
			if ($lock_mode == 0)
			{
				$template = $template = new template("loginmodule","_newuser_appove_success_email");
				$template->assign("user",$mu);
				$html=$template->render();
				///
				if (!defined('SYS_SMTP')) require_once(BASE.'subsystems/smtp.php');
				@exponent_smtp_mail($mu->email,SITE_TITLE.' <'.SMTP_FROMADDRESS.'>',"Welcome to " . SITE_TITLE,$html);
			}
			//
			echo $id; // return $id; hehe
		}
	}
	else
	{
		echo "";
	}
?>
